home *** CD-ROM | disk | FTP | other *** search
- package com.ibm.uvm.abt.edit;
-
- import java.awt.Rectangle;
- import java.beans.PropertyEditorSupport;
- import java.util.ResourceBundle;
-
- public class RectanglePropertyEditor extends PropertyEditorSupport {
- private static ResourceBundle resabtedit = ResourceBundle.getBundle("com/ibm/uvm/abt/edit/abtedit");
-
- public String getAsText() {
- if (((PropertyEditorSupport)this).getValue() instanceof String) {
- return (String)((PropertyEditorSupport)this).getValue();
- } else if (((PropertyEditorSupport)this).getValue() == null) {
- return "";
- } else {
- Rectangle rect = (Rectangle)((PropertyEditorSupport)this).getValue();
- return "" + rect.x + ", " + rect.y + ", " + rect.width + ", " + rect.height;
- }
- }
-
- public String getJavaInitializationString() {
- Rectangle rect = (Rectangle)((PropertyEditorSupport)this).getValue();
- return rect == null ? "new java.awt.Rectangle(0,0,0,0)" : "new java.awt.Rectangle(" + rect.x + ", " + rect.y + ", " + rect.width + ", " + rect.height + ")";
- }
-
- private Rectangle parseForRectangle(String text) throws Exception, NumberFormatException {
- int x = text.indexOf(",");
- if (x < 0) {
- throw new Exception(resabtedit.getString("Rect_num_must_be_sep"));
- } else {
- String xText = text.substring(0, x);
- String remains = text.substring(x + ",".length());
- int y = remains.indexOf(",");
- if (y < 0) {
- throw new Exception(resabtedit.getString("Rect_num_must_be_sep"));
- } else {
- String yText = remains.substring(0, y);
- remains = remains.substring(y + ",".length());
- int w = remains.indexOf(",");
- if (w < 0) {
- throw new Exception(resabtedit.getString("Rect_num_must_be_sep"));
- } else {
- String wText = remains.substring(0, w);
- String hText = remains.substring(w + ",".length());
- return new Rectangle(Integer.valueOf(xText.trim()), Integer.valueOf(yText.trim()), Integer.valueOf(wText.trim()), Integer.valueOf(hText.trim()));
- }
- }
- }
- }
-
- public void setAsText(String text) throws IllegalArgumentException {
- if (text instanceof String) {
- try {
- ((PropertyEditorSupport)this).setValue(this.parseForRectangle(text));
- } catch (Exception var3) {
- throw new IllegalArgumentException(((Throwable)var3).getMessage());
- }
- } else {
- throw new IllegalArgumentException(text);
- }
- }
- }
-